package iq.jfreechart;

import java.awt.Font;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;

public class Test {
	public static void main(String[] args) throws FileNotFoundException,
			IOException {
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();

		dataset.addValue(610, "广州", "猪肉");

		dataset.addValue(220, "广州", "牛肉");

		dataset.addValue(530, "广州", "鸡肉");

		dataset.addValue(340, "广州", "鱼肉");

		dataset.addValue(810, "北京", "猪肉");

		dataset.addValue(420, "北京", "牛肉");

		dataset.addValue(630, "北京", "鸡肉");

		dataset.addValue(540, "北京", "鱼肉");

		JFreeChart chart = ChartFactory.createBarChart3D("肉类销量统计 图",
		"肉类",
		"销量",
		dataset,
		PlotOrientation.VERTICAL,
		true,
		false,
		false);
		
		TextTitle textTitle = chart.getTitle();
		textTitle.setFont(new Font("黑体", Font.PLAIN, 20));
		CategoryPlot plot = chart.getCategoryPlot();// 获得图表区域对象
		CategoryAxis domainAxis = plot.getDomainAxis();
		//domainAxis.setVisible(true);
		//plot.setDomainAxis(domainAxis);
		ValueAxis rAxis = plot.getRangeAxis();
		/*------设置X轴坐标上的文字-----------*/
		domainAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 15));
		/*------设置X轴的标题文字------------*/
		domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 15));
		/*------设置Y轴坐标上的文字-----------*/
		rAxis.setTickLabelFont(new Font("黑体", Font.PLAIN, 15));
		/*------设置Y轴的标题文字------------*/
		rAxis.setLabelFont(new Font("黑体", Font.PLAIN, 15));
		
		LegendTitle legendTitle = chart.getLegend();
		legendTitle.setItemFont(new Font("黑体", Font.PLAIN, 13));
		ChartUtilities.writeChartAsPNG(
				new FileOutputStream("c:/chart/test.png"), chart, 500, 500);

	}
}
